package com.tuo51.evaluate.repositories.article;

import com.tuo51.evaluate.domain.news.ArticleCategory;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@CacheConfig(cacheNames = "ArticleCategoryRepository")
public interface ArticleCategoryRepository extends JpaRepository<ArticleCategory, String>, JpaSpecificationExecutor<ArticleCategory> {

    @Cacheable(keyGenerator = "keyGenerator")
    List<ArticleCategory> findAllByChannelAndDeletedIsFalseAndParentIsNullOrderByOrderWeightDesc(String channel);

    @Cacheable(keyGenerator = "keyGenerator")
    List<ArticleCategory> findAllByChannelAndDeletedIsFalseAndParentIsNullAndHiddenIsFalseOrderByOrderWeightDesc(String channel);

//    @Cacheable(keyGenerator = "keyGenerator")
    ArticleCategory findByTitleAndChannelAndParentIdAndDeletedIsFalse(String title, String channel, String parentId);

//    @Cacheable(keyGenerator = "keyGenerator")
    ArticleCategory findTop1ByTitleAndChannelAndDeletedIsFalse(String title, String channel);

//    @Cacheable(keyGenerator = "keyGenerator")
    ArticleCategory findByTitleAndChannelAndParentIdIsNullAndDeletedIsFalse(String title, String channel);

//    @Cacheable(keyGenerator = "keyGenerator")
    ArticleCategory findByStaticCodeAndDeletedIsFalse(String staticCode);
}
